﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MySpace.Data;

/// <summary>
///GuestBookTable 的摘要说明
/// </summary>
namespace DataBaseTable
{
    public class GuestBookTable : DBTable
    {
        private const string tableName = "hwguestbook";//表名

        public GuestBookTable()
            : base(GetHandler.Init(), tableName)
        {
            this.GetRow();
            //没有参数重载
        }
        public GuestBookTable(int id):base(GetHandler.Init(), tableName)
        {
            this.Filter = "id=?";
            this.AddParameter("id", id);
            this.GetRow();
        }
        /// <summary>
        /// 姓名
        /// </summary>
        public string Name
        {
            get
            {
                try { return (string)this.DataRow["Name"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["Name"] = value;
            }
        }
        /// <summary>
        /// Email
        /// </summary>
        public string Email
        {
            get
            {
                try { return (string)this.DataRow["Email"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["Email"] = value;
            }
        }
        /// <summary>
        /// 留言内容
        /// </summary>
        public string Content
        {
            get
            {
                try { return (string)this.DataRow["Content"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["Content"] = value;
            }
        }
        /// <summary>
        /// 时间
        /// </summary>
        public DateTime theDate
        {
            get
            {
                try { return (DateTime)this.DataRow["theDate"]; }
                catch { return DateTime.Now; }
            }
        }
        /// <summary>
        /// 回复
        /// </summary>
        public string Reply
        {
            get
            {
                try { return (string)this.DataRow["Reply"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["Reply"] = value;
            }
        }
        /// <summary>
        /// 回复时间
        /// </summary>
        public DateTime ReplyDate
        {
            get
            {
                try { return (DateTime)this.DataRow["ReplyDate"]; }
                catch { return DateTime.Now; }
            }
        }
        /// <summary>
        /// Ip
        /// </summary>
        public string Ip
        {
            get
            {
                try { return (string)this.DataRow["Ip"]; }
                catch { return string.Empty; }
            }
            set
            {
                this.DataRow["Ip"] = value;
            }
        }
        /// <summary>
        /// 置顶
        /// </summary>
        public int IsTop
        {
            get
            {
                try { return (int)this.DataRow["IsTop"]; }
                catch { return 0; }
            }
            set
            {
                this.DataRow["IsTop"] = value;
            }
        }
        /// <summary>
        /// 检测时间隔间
        /// </summary>
        /// <returns>false过短,TRUE满足</returns>
        public bool CheckTimeSpace(string ip, int timespace)
        {
            DateTime newDate = DateTime.Now.AddSeconds(-1*timespace);
            DBHandler dbh = GetHandler.Init();
            dbh.CommandText="select top 1 ip from hwguestbook where ip = '"+ip+"' and theDate > #"+ newDate +"#";
            if (dbh.ExecuteDataTable().Rows.Count > 0)
                return false;
            else
                return true;
        }
    }
}